<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>农资商城销售系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" th:href="@{/admin/css/font.css}">
    <link rel="stylesheet" th:href="@{/admin/css/layui.css}">
    <link rel="stylesheet" th:href="@{/admin/css/xadmin.css}">
    <script type="text/javascript" th:src="@{/admin/js/jquery-3.5.1.min.js}"></script>
    <script type="text/javascript" th:src="@{/admin/lib/layui/layui.js}"></script>
    <script type="text/javascript" th:src="@{/admin/js/global.js}"></script>
    <script type="text/javascript" th:src="@{/admin/js/layui.js}"></script>
    <script type="text/javascript" th:src="@{/admin/js/xadmin.js}"></script>
    <style>
        /* 使用CSS样式来定义左右两部分的宽度和布局 */
        .leftRight-section {
            width: 100%; /* 左边个人信息部分的宽度 */
            float: left; /* 左浮动 */
            padding: 20px; /* 可根据需要调整 */
        }
    </style>
</head>
<body>


<div class="layui-fluid">
    <div class="layui-row">
        <div class="leftRight-section">
        <form class="layui-form">
            <div class="layui-form-item" style="display: none;">
                <label for="id" class="layui-form-label">
                    <span class="x-red">*</span>ID</label>
                <div class="layui-input-inline">
                    <input type="text" th:value="${user.id}" id="id" name="id" autocomplete="off" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="phone" class="layui-form-label">
                    <span class="x-red">*</span>手机号</label>
                <div class="layui-input-inline">
                    <input type="text" th:value="${user.phone}" id="phone" name="phone" lay-verify="required" autocomplete="off"
                           class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="password" class="layui-form-label">
                    <span class="x-red">*</span>密码</label>
                <div class="layui-input-inline">
                    <input type="password" th:value="${user.password}" id="password" name="password" lay-verify="required" autocomplete="off"
                           class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="repassword" class="layui-form-label">
                    <span class="x-red">*</span>重复密码</label>
                <div class="layui-input-inline">
                    <input type="password" th:value="${user.password}" id="repassword" name="repassword" lay-verify="required" autocomplete="off"
                           class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>姓名</label>
                <div class="layui-input-inline">
                    <input type="text" th:value="${user.username}" id="username" name="username" lay-verify="required"
                           autocomplete="off" class="layui-input"></div>
            </div>

            <div class="layui-form-item">
                <label for="birthday" class="layui-form-label">生日</label>
                <div class="layui-input-inline">
                    <input type="text" th:value="${birthday}" id="birthday" name="birthday"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="update" lay-submit>修改</button>
            </div>
        </form>
        </div>
    </div>
</div>
<script>layui.use(['form', 'layer', 'jquery','table','laydate'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        var table = layui.table;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#birthday',
        });

        //监听提交
        form.on('submit(update)', function (data) {
            //验证account是否是手机号格式
            if (!(/^1[3456789]\d{9}$/.test(data.field.phone))) {
                layer.msg('手机号格式不正确', {
                    icon: 5,
                    time: 2000
                });
                return false;
            }
            //验证两次密码是否一致
            if (data.field.password !== data.field.repassword) {
                layer.msg('两次密码不一致', {
                    icon: 5,
                    time: 2000
                });
                return false;
            }
            $.post(prefix+'/admininfo/update', data.field, function (res) {
                if (res.code === 200) {
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 2000
                    }, function () {
                        setUserName( data.field.username)
                        //刷新父页面
                        parent.location.reload();
                    });
                } else {
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 2000
                    });
                }
            })
            return false;
        });

    });</script>
</body>

</html>